﻿@{
    ViewBag.Title = "编辑图文回复";
    List<SelectListItem> weixinListItems = ViewBag.weixinListItems;
}
@model DTcms.Model.weixin_request_rule
<form id="form1" class="layui-form" url="PictureSave?action=@ViewBag.action&id=@ViewBag.id">
    @Html.AntiForgeryToken()
    <!--内容-->
    <div class="layui-fluid">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title" id="floatHead">
                <li class="layui-this">图文回复</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label">公众账户</label>
                        <div class="layui-input-block">
                            <select class="select" name="account_id" url="/webapi/weixinJson" selectValue="@Model.account_id" promtion="请选择公众账户" datatype="*" errormsg="请选择公众账户！" sucmsg=" "><option value="">请选择公众账户...</option></select>
                            <span class="Validform_checktip">*当前的公众账户，可以切换。</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">搜索关键词</label>
                        <div class="layui-input-block">
                            @Html.TextBox("keywords", Model.keywords, new { @class = "input normal ", datatype = "*1-1000", sucmsg = " ", nullmsg = "请填写关键词，多个关键词请用|格开：例如: 美丽|漂亮|好看" })
                            <span class="Validform_checktip">*多个关键词请用|格开：例如: 美丽|漂亮|好看</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">关键词类型</label>
                        <div class="layui-input-block">
                            @Html.RadioButton("is_like_query", 0, Model.is_like_query == 0, new { title = "完全匹配" })
                            @Html.RadioButton("is_like_query", 1, Model.is_like_query == 1, new { title = "包含匹配" })
                            <span class="Validform_checktip">*包含匹配，当文字包含本关键词时触发</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序数字</label>
                        <div class="layui-input-block">
                            @Html.TextBox("sort_id", Model.sort_id, new { @class = "input small", datatype = "n", sucmsg = " " })
                            <span class="Validform_checktip">*数字，越小越向前</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图文列表</label>
                        <div class="layui-input-block">
                            <a id="itemAddButton" class="layui-btn layui-btn-primary icon-btn"><i class="iconfont icon-add"></i> 添加图片</a>
                            <span class="Validform_checktip">*微信规定图片数量最多10张。</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <div class="table-container">
                                <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="100%">
                                    <thead>
                                        <tr>
                                            <th width="12%">图片</th>
                                            <th width="20%">标题</th>
                                            <th width="40%">链接</th>
                                            <th width="12%">排序</th>
                                            <th width="10%">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="item_box">
                                        @if (Model.contents != null)
                                        {
                                            foreach (DTcms.Model.weixin_request_content item in Model.contents)
                                            {
                                                <tr class="td_c">
                                                    <td>
                                                        <input type="hidden" name="item_id" value="@item.id" />
                                                        <input type="hidden" name="item_content" value="@item.content" />
                                                        <input type="hidden" name="item_imgurl" value="@item.img_url" />
                                                        <span class="item_imgurl img-box">
                                                            @if (item.img_url.ToString() == "")
                                                            {
                                                                @:-
                                                            }
                                                            else
                                                            {
                                                                <img src="@item.img_url" />
                                                            }
                                                        </span>
                                                    </td>
                                                    <td>
                                                        <input type="hidden" name="item_title" value="@item.title" />
                                                        <span class="item_title">@item.title</span>
                                                    </td>
                                                    <td>
                                                        <input type="hidden" name="item_linkurl" value="@item.link_url" />
                                                        <span class="item_linkurl">@item.link_url</span>
                                                    </td>
                                                    <td>
                                                        <input type="hidden" name="item_sortid" value="@item.sort_id" />
                                                        <span class="item_sortid">@item.sort_id</span>
                                                    </td>
                                                    <td>
                                                        <a title="编辑" class="img-btn edit operator" onclick="showImgDialog(this);">编辑</a>
                                                        <a title="删除" class="img-btn del operator" onclick="delItemTr(this);">删除</a>
                                                    </td>
                                                </tr>
                                            }
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--/内容-->
    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-wrap">
            <button class="layui-btn icon-btn" id="btnSubmit"><i class="layui-icon layui-icon-ok"></i>提交保存</button>
            <input name="btnReturn" type="button" value="返回上一页" class="layui-btn layui-btn-warm" onclick="javascript: history.back(-1);" />
        </div>
    </div>
    <!--/工具栏-->
</form>
@section Scripts{
    <script type="text/javascript">
        layui.use(['validform', 'element', 'jqueryform', 'cascadeSelect'], function () {
            var cascadeSelect = layui.cascadeSelect, $ = layui.jquery;
            cascadeSelect.init('account_id', false);
            //初始化表单验证
            $("#form1").initValidform('#btnSubmit', 1);

            //添加按钮(点击绑定)
            $("#itemAddButton").click(function () {
                showImgDialog();
            });
        });
        //创建窗口
        function showImgDialog(obj) {
            var objNum = arguments.length;
            var d = layer.open({
                type: 2,
                area: ['520px', '430px'],
                title: "添加图片",
                maxmin: true,
                content: '../dialog/dialog_picture',
                btn: ["确定", '关闭'],
                btn1: function (index, layero) {
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    var trHtml = iframeWin.execPicHtml(obj);
                    if (trHtml.length > 0) {
                        $("#item_box").append(trHtml);
                        layer.close(index);
                    }
                },
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    //检查是否修改状态
                    if (objNum == 1) {
                        iframeWin.submitValue(obj);
                    }
                },
                cancel: function (index, layero) { }
            });
        }

        //删除节点
        function delItemTr(obj) {
            $(obj).parent().parent().remove();
        }
    </script>
}